package portlet.dsct;

import java.io.IOException;

import java.sql.Timestamp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import java.util.TimeZone;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.ValueExpression;

import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UISelectItems;
import javax.faces.context.FacesContext;
import javax.faces.convert.DateTimeConverter;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequest;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import oracle.adf.model.binding.DCIteratorBinding;
import oracle.adf.view.rich.component.rich.data.RichColumn;
import oracle.adf.view.rich.component.rich.data.RichTable;
import oracle.adf.view.rich.component.rich.input.RichInputDate;
import oracle.adf.view.rich.component.rich.input.RichInputText;
import oracle.adf.view.rich.component.rich.input.RichSelectOneChoice;
import oracle.adf.view.rich.component.rich.layout.RichPanelFormLayout;
import oracle.adf.view.rich.component.rich.layout.RichPanelGroupLayout;
import oracle.adf.view.rich.component.rich.layout.RichPanelTabbed;
import oracle.adf.view.rich.component.rich.layout.RichShowDetailItem;
import oracle.adf.view.rich.component.rich.nav.RichCommandButton;
import oracle.adf.view.rich.component.rich.nav.RichCommandLink;
import oracle.adf.view.rich.component.rich.nav.RichGoLink;
import oracle.adf.view.rich.component.rich.output.RichOutputText;
import oracle.adf.view.rich.context.AdfFacesContext;

import oracle.jbo.Row;
import oracle.jbo.RowSet;
import oracle.jbo.domain.ClobDomain;
import oracle.jbo.domain.Number;

import oracle.portlet.bridge.adf.application.ADFBridgePortlet;

import org.apache.myfaces.trinidad.model.RowKeySet;
import org.apache.myfaces.trinidad.model.RowKeySetImpl;
import org.apache.myfaces.trinidadinternal.taglib.util.MethodExpressionMethodBinding;

import portlet.common.Utils;
import portlet.common.search.AdvancedSearchGroup;
import portlet.common.search.AdvancedSearchItem;


public class Dsct extends ADFBridgePortlet {
    private RichTable tableDonVi = new RichTable();
    private RichPanelFormLayout searchPanel = new RichPanelFormLayout();
    private RichPanelGroupLayout pagingPanel = new RichPanelGroupLayout();

    protected String getTitle(RenderRequest request) {
        // Get the customized title. This defaults to the declared title.
        PortletPreferences prefs = request.getPreferences();
        return prefs.getValue(PORTLETTITLE_KEY, super.getTitle(request));
    }
    public static final String APPLY_ACTION = "apply_action";
    public static final String OK_ACTION = "ok_action";
    public static final String PORTLETTITLE_KEY = "portletTitle";
    private static final String DEFAULT_LANGCODE = "vi";
    private final String SEARCH_ID_PREFIX = "search";
    private final String UPDATE_ID_PREFIX = "update";
    private final String ROW_KEY = "rowkey";
    private final String FILE_GROUP_ID_SUBFIX = "group";
    private final String FILE_LABEL_ID_SUBFIX = "label";
    private final String FILE_REMOVE_ID_SUBFIX = "remove";
    private final String LINK_DES = "des";

    private String[] buildValueArray(String values) {
        if (values.indexOf(',') < 0) {
            return new String[] { values };
        }
        StringTokenizer st = new StringTokenizer(values, ",");
        String[] valueArray = new String[st.countTokens()];
        int i = 0;
        while (st.hasMoreTokens()) {
            valueArray[i] = st.nextToken().trim();
            i++;
        }
        return valueArray;
    }

    public void processAction(ActionRequest request,
                              ActionResponse response) throws PortletException,
                                                              IOException {
        request.setAttribute("javax.portlet.config", getPortletConfig());
        super.processAction(request, response);
    }

    public void render(RenderRequest request,
                       RenderResponse response) throws PortletException,
                                                       IOException {
        request.setAttribute("javax.portlet.config", getPortletConfig());
        super.render(request, response);
    }

    @Override
    protected void doView(RenderRequest renderRequest,
                          RenderResponse renderResponse) throws PortletException,
                                                                IOException {
        renderRequest.getPortletSession().setAttribute("reset", 1);
        checkParameter(renderRequest);
        super.doView(renderRequest, renderResponse);
    }

    public boolean checkParameter(RenderRequest request) {
        boolean check = true;
        String pLoaiDonViId = request.getParameter("loaidonviid");
        String pLangCode = request.getParameter("langcode");
        String pChiTietUrl = request.getParameter("chitieturl");
        String sLoaiDonViId =
            (String)request.getPortletSession().getAttribute("loaidonviid");
        String sLangCode =
            (String)request.getPortletSession().getAttribute("langcode");
        String sChiTietUrl =
            (String)request.getPortletSession().getAttribute("chitieturl");
        if (pLangCode == null) {
            pLangCode = DEFAULT_LANGCODE;
        }
        if (sLoaiDonViId != null && pLoaiDonViId != null) {
            if (sLoaiDonViId.equals(pLoaiDonViId) == false) {
                check = false;
            }
        } else if (pLoaiDonViId != null) {
            check = false;
        } else if (sLoaiDonViId != null) {
            check = false;
        }

        if (sLangCode != null && pLangCode != null) {
            if (sLangCode.equals(pLangCode) == false) {
                check = false;
            }
        } else if (pLangCode != null) {
            check = false;
        } else if (sLangCode != null) {
            check = false;
        }

        if (sChiTietUrl != null && pChiTietUrl != null) {
            if (sChiTietUrl.equals(pChiTietUrl) == false) {
                check = false;
            }
        } else if (pChiTietUrl != null) {
            check = false;
        } else if (sChiTietUrl != null) {
            check = false;
        }
        request.getPortletSession().setAttribute("loaidonviid", pLoaiDonViId);
        request.getPortletSession().setAttribute("langcode", pLangCode);
        request.getPortletSession().setAttribute("chitieturl", pChiTietUrl);
        return check;
    }

    public String getResetForm() {
        PortletRequest request =
            (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        Integer reset =
            (Integer)request.getPortletSession().getAttribute("reset");
        if (reset != null && reset.intValue() == 1) {
            resetIterator(request);
            createForm();
            getValue(1);
            request.getPortletSession().setAttribute("reset", 0);
        }
        return null;
    }

    public void timKiem(ActionEvent actionEvent) {
        if (searchPanel.getChildren().size() > 0) {
            PortletRequest request =
                (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
            String loaiDonViId =
                (String)request.getPortletSession().getAttribute("loaidonviid");
            String langCode =
                (String)request.getPortletSession().getAttribute("langcode");
            if (langCode == null) {
                langCode = DEFAULT_LANGCODE;
            }
            List<UIComponent> listUIComponent = new ArrayList();
            List<UIComponent> listDetailItem = new ArrayList();
            List<UIComponent> listDetailItemNext = new ArrayList();
            listDetailItemNext.add(searchPanel);
            while (listDetailItemNext.size() > 0) {
                listDetailItem = listDetailItemNext;
                listDetailItemNext = new ArrayList();
                for (UIComponent loopComponent : listDetailItem) {
                    if (loopComponent != null) {
                        if (loopComponent instanceof RichPanelTabbed ||
                            loopComponent instanceof RichShowDetailItem ||
                            loopComponent instanceof RichPanelFormLayout) {
                            if (loopComponent.getChildCount() > 0) {
                                listDetailItemNext.addAll(loopComponent.getChildren());
                            }
                        }
                        if (loopComponent instanceof RichInputText ||
                            loopComponent instanceof RichInputDate ||
                            loopComponent instanceof RichSelectOneChoice) {
                            listUIComponent.add(loopComponent);
                        }
                    }
                }
            }

            List<AdvancedSearchGroup> listASG = new ArrayList();
            AdvancedSearchGroup asgTrangThai = new AdvancedSearchGroup();
            listASG.add(asgTrangThai);
            AdvancedSearchItem asiTrangThai = new AdvancedSearchItem();
            asgTrangThai.getListChildren().add(asiTrangThai);
            asiTrangThai.setItemName("TrangThai");
            asiTrangThai.setRequired(true);
            asiTrangThai.getListValue().add(0,
                                            new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
            AdvancedSearchGroup asgLoaiTruongTt = new AdvancedSearchGroup();
            listASG.add(asgLoaiTruongTt);
            AdvancedSearchItem asiLoaiTruongTt = new AdvancedSearchItem();
            asgLoaiTruongTt.getListChildren().add(asiLoaiTruongTt);
            asiLoaiTruongTt.setItemName("DlctLoaiTruongTt");
            asiLoaiTruongTt.setRequired(true);
            asiLoaiTruongTt.getListValue().add(0,
                                               new Number(Utils.ENUM_LOAI_TRUONG_TT.DON_VI.getId()));
            if (loaiDonViId != null) {
                try {
                    Number loaiDonViNumber = new Number(loaiDonViId);
                    AdvancedSearchGroup asg = new AdvancedSearchGroup();
                    listASG.add(asg);
                    AdvancedSearchItem asi = new AdvancedSearchItem();
                    asg.getListChildren().add(asi);
                    asi.setItemName("DlctLdvTtView");
                    asi.setRequired(true);
                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                    AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                    asi.getListChildren().add(asgChild);
                    AdvancedSearchItem asiChild = new AdvancedSearchItem();
                    asgChild.getListChildren().add(asiChild);
                    asiChild.setItemName("DlctLoaiDonViId");
                    asiChild.setRequired(true);
                    asiChild.getListValue().add(loaiDonViNumber);
                } catch (Exception e) {
                }
            }
            if (langCode != null) {
                try {
                    AdvancedSearchGroup asg = new AdvancedSearchGroup();
                    listASG.add(asg);
                    AdvancedSearchItem asi = new AdvancedSearchItem();
                    asg.getListChildren().add(asi);
                    asi.setItemName("DlctNgonNguView");
                    asi.setRequired(true);
                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                    AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                    asi.getListChildren().add(asgChild);
                    AdvancedSearchItem asiChild = new AdvancedSearchItem();
                    asgChild.getListChildren().add(asiChild);
                    asiChild.setItemName("Ma");
                    asiChild.setRequired(true);
                    asiChild.getListValue().add(langCode);
                } catch (Exception e) {
                }
            }
            Utils.searchadvanced("DlctTruongTtView1Iterator", listASG);
            DCIteratorBinding truongTtView1Iterator =
                Utils.getIteratorBinding("DlctTruongTtView1Iterator");
            
            
             listASG = new ArrayList();
             asgTrangThai = new AdvancedSearchGroup();
            listASG.add(asgTrangThai);
            asiTrangThai = new AdvancedSearchItem();
            asgTrangThai.getListChildren().add(asiTrangThai);
            asiTrangThai.setItemName("TrangThai");
            asiTrangThai.setRequired(true);
            asiTrangThai.getListValue().add(0,
                                            new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
            if (loaiDonViId != null) {
                try {
                    Number loaiDonViNumber = new Number(loaiDonViId);
                    AdvancedSearchGroup asg = new AdvancedSearchGroup();
                    listASG.add(asg);
                    AdvancedSearchItem asi = new AdvancedSearchItem();
                    asg.getListChildren().add(asi);
                    asi.setItemName("DlctDvLdvView");
                    asi.setRequired(true);
                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                    AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                    asi.getListChildren().add(asgChild);
                    AdvancedSearchItem asiChild = new AdvancedSearchItem();
                    asgChild.getListChildren().add(asiChild);
                    asiChild.setItemName("DlctLoaiDonViId");
                    asiChild.setRequired(true);
                    asiChild.getListValue().add(loaiDonViNumber);
                } catch (Exception e) {
                }
            }
            if (langCode != null) {
                try {
                    AdvancedSearchGroup asg = new AdvancedSearchGroup();
                    listASG.add(asg);
                    AdvancedSearchItem asi = new AdvancedSearchItem();
                    asg.getListChildren().add(asi);
                    asi.setItemName("DlctDvNnView");
                    asi.setRequired(true);
                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                    AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                    asi.getListChildren().add(asgChild);
                    AdvancedSearchItem asiChild = new AdvancedSearchItem();
                    asgChild.getListChildren().add(asiChild);
                    asiChild.setItemName("DlctNgonNguView");
                    asiChild.setRequired(true);
                    asiChild.setOperator(AdvancedSearchItem.OPER_EXISTS);
                    AdvancedSearchGroup asgChild2 = new AdvancedSearchGroup();
                    asiChild.getListChildren().add(asgChild2);
                    AdvancedSearchItem asiChild2 = new AdvancedSearchItem();
                    asgChild2.getListChildren().add(asiChild2);
                    asiChild2.setItemName("Ma");
                    asiChild2.setRequired(true);
                    asiChild2.getListValue().add(langCode);
                } catch (Exception e) {
                }
            }

            for (UIComponent ui : listUIComponent) {
                if (ui.getId() != null) {
                    String rowKey =
                        (String)ui.getAttributes().get("rowKey");
                    truongTtView1Iterator.setCurrentRowWithKey(rowKey);
                    Row truongTtRow = truongTtView1Iterator.getCurrentRow();
                    if (truongTtRow != null) {
                        Row loopRow = truongTtRow;
                        Row rootRow = null;
                        while (loopRow != null) {
                            rootRow = loopRow;
                            loopRow =
                                    (Row)loopRow.getAttribute("DlctTruongTtTuIdDlctTruongTtView");
                        }
                        Number id = (Number)rootRow.getAttribute("Id");
                        Number kieuDuLieu =
                            (Number)truongTtRow.getAttribute("KieuDuLieu");
                        if (kieuDuLieu != null) {
                            int kieu = kieuDuLieu.intValue();
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        Number valNumber =
                                            new Number(valObject);
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtDvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValNumber");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valNumber);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            getResource("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        String valString = (String)valObject;
                                        valString = valString.toUpperCase().trim();
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtDvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValVarchar");
                                        asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                        asiChild.setUpperColumns(true);
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valString);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            getResource("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        String valString = (String)valObject;
                                        valString = valString.toUpperCase().trim();
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtDvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValVarchar");
                                        asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                        asiChild.setUpperColumns(true);
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valString);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            getResource("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        String valString = (String)valObject;
                                        valString = valString.toUpperCase().trim();
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtDvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValVarchar");
                                        asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                        asiChild.setUpperColumns(true);
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valString);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            getResource("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                RichInputDate inputDate = (RichInputDate)ui;
                                Object valObject = inputDate.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        java.util.Date javaDate =
                                            (java.util.Date)valObject;
                                        Timestamp timestamp =
                                            new Timestamp(javaDate.getTime());
                                        oracle.jbo.domain.Date valDate =
                                            new oracle.jbo.domain.Date(timestamp);
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtDvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValDate");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valDate);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            getResource("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        String valString = (String)valObject;
                                        valString = valString.toUpperCase().trim();
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtDvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValClob");
                                        asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                        asiChild.setUpperColumns(true);
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valString);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            getResource("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        String valString = (String)valObject;
                                        valString = valString.toUpperCase().trim();
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtDvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("HtFileView");
                                        asiChild.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        asiChild.setRequired(true);

                                        AdvancedSearchGroup asgFile =
                                            new AdvancedSearchGroup();
                                        asiChild.getListChildren().add(asgFile);
                                        AdvancedSearchItem asiFile =
                                            new AdvancedSearchItem();
                                        asgFile.getListChildren().add(asiFile);
                                        asiFile.setItemName("TenFile");
                                        asiFile.setRequired(true);
                                        asiFile.getListValue().add(valString);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            getResource("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.LOAI_CHUNG_KHOAN.getId()) {
                                RichSelectOneChoice selectOneChoice =
                                    (RichSelectOneChoice)ui;
                                Object valObject = selectOneChoice.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        Number valNumber =
                                            new Number(valObject);
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtDvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctLoaiChungKhoanId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valNumber);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            getResource("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.SAN_GIAO_DICH.getId()) {
                                RichSelectOneChoice selectOneChoice =
                                    (RichSelectOneChoice)ui;
                                Object valObject = selectOneChoice.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        Number valNumber =
                                            new Number(valObject);
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtDvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctSanGiaoDichId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valNumber);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            getResource("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Utils.searchadvanced("DlctDonViView1Iterator", listASG);
            getValue(0);
            AdfFacesContext.getCurrentInstance().addPartialTarget(tableDonVi);
            AdfFacesContext.getCurrentInstance().partialUpdateNotify(tableDonVi);
        }
    }

    public void changePage(ActionEvent actionEvent) {
        Integer pageNum =
            (Integer)actionEvent.getComponent().getAttributes().get("pageNum");
        if (pageNum == null) {
            pageNum = 1;
        }
        getValue(pageNum.intValue());
    }

    private void resetIterator(PortletRequest request) {
        String loaiDonViId =
            (String)request.getPortletSession().getAttribute("loaidonviid");
        String langCode =
            (String)request.getPortletSession().getAttribute("langcode");
        if (langCode == null) {
            langCode = DEFAULT_LANGCODE;
        }
        List<AdvancedSearchGroup> listASG = new ArrayList();
        AdvancedSearchGroup asgTrangThai = new AdvancedSearchGroup();
        listASG.add(asgTrangThai);
        AdvancedSearchItem asiTrangThai = new AdvancedSearchItem();
        asgTrangThai.getListChildren().add(asiTrangThai);
        asiTrangThai.setItemName("TrangThai");
        asiTrangThai.setRequired(true);
        asiTrangThai.getListValue().add(0,
                                        new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
        Utils.searchadvanced("DlctSanGiaoDichView1Iterator", listASG);
        Utils.searchadvanced("DlctLoaiChungKhoanView1Iterator", listASG);

        listASG = new ArrayList();
        asgTrangThai = new AdvancedSearchGroup();
        listASG.add(asgTrangThai);
        asiTrangThai = new AdvancedSearchItem();
        asgTrangThai.getListChildren().add(asiTrangThai);
        asiTrangThai.setItemName("TrangThai");
        asiTrangThai.setRequired(true);
        asiTrangThai.getListValue().add(0,
                                        new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
        if (loaiDonViId != null) {
            try {
                Number loaiDonViNumber = new Number(loaiDonViId);
                AdvancedSearchGroup asg = new AdvancedSearchGroup();
                listASG.add(asg);
                AdvancedSearchItem asi = new AdvancedSearchItem();
                asg.getListChildren().add(asi);
                asi.setItemName("DlctDvLdvView");
                asi.setRequired(true);
                asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                asi.getListChildren().add(asgChild);
                AdvancedSearchItem asiChild = new AdvancedSearchItem();
                asgChild.getListChildren().add(asiChild);
                asiChild.setItemName("DlctLoaiDonViId");
                asiChild.setRequired(true);
                asiChild.getListValue().add(loaiDonViNumber);
                
                asiChild = new AdvancedSearchItem();
                asgChild.getListChildren().add(asiChild);
                asiChild.setItemName("DlctLoaiDonViView");
                asiChild.setRequired(true);
                asiChild.setOperator(AdvancedSearchItem.OPER_EXISTS);
                asiChild.getListChildren().add(asgTrangThai);
                
            } catch (Exception e) {
            }
        }
        if (langCode != null) {
            try {
                AdvancedSearchGroup asg = new AdvancedSearchGroup();
                listASG.add(asg);
                AdvancedSearchItem asi = new AdvancedSearchItem();
                asg.getListChildren().add(asi);
                asi.setItemName("DlctDvNnView");
                asi.setRequired(true);
                asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                asi.getListChildren().add(asgChild);
                AdvancedSearchItem asiChild = new AdvancedSearchItem();
                asgChild.getListChildren().add(asiChild);
                asiChild.setItemName("DlctNgonNguView");
                asiChild.setRequired(true);
                asiChild.setOperator(AdvancedSearchItem.OPER_EXISTS);
                AdvancedSearchGroup asgChild2 = new AdvancedSearchGroup();
                asiChild.getListChildren().add(asgChild2);
                AdvancedSearchItem asiChild2 = new AdvancedSearchItem();
                asgChild2.getListChildren().add(asiChild2);
                asiChild2.setItemName("Ma");
                asiChild2.setRequired(true);
                asiChild2.getListValue().add(langCode);
            } catch (Exception e) {
            }
        }
        Utils.searchadvanced("DlctDonViView1Iterator", listASG);

        listASG = new ArrayList();
        asgTrangThai = new AdvancedSearchGroup();
        listASG.add(asgTrangThai);
        asiTrangThai = new AdvancedSearchItem();
        asgTrangThai.getListChildren().add(asiTrangThai);
        asiTrangThai.setItemName("TrangThai");
        asiTrangThai.setRequired(true);
        asiTrangThai.getListValue().add(0,
                                        new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
        AdvancedSearchGroup asgLoaiTruongTt = new AdvancedSearchGroup();
        listASG.add(asgLoaiTruongTt);
        AdvancedSearchItem asiLoaiTruongTt = new AdvancedSearchItem();
        asgLoaiTruongTt.getListChildren().add(asiLoaiTruongTt);
        asiLoaiTruongTt.setItemName("DlctLoaiTruongTt");
        asiLoaiTruongTt.setRequired(true);
        asiLoaiTruongTt.getListValue().add(0,
                                           new Number(Utils.ENUM_LOAI_TRUONG_TT.DON_VI.getId()));
        if (loaiDonViId != null) {
            try {
                Number loaiDonViNumber = new Number(loaiDonViId);
                AdvancedSearchGroup asg = new AdvancedSearchGroup();
                listASG.add(asg);
                AdvancedSearchItem asi = new AdvancedSearchItem();
                asg.getListChildren().add(asi);
                asi.setItemName("DlctLdvTtView");
                asi.setRequired(true);
                asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                asi.getListChildren().add(asgChild);
                AdvancedSearchItem asiChild = new AdvancedSearchItem();
                asgChild.getListChildren().add(asiChild);
                asiChild.setItemName("DlctLoaiDonViId");
                asiChild.setRequired(true);
                asiChild.getListValue().add(loaiDonViNumber);
            } catch (Exception e) {
            }
        }
        if (langCode != null) {
            try {
                AdvancedSearchGroup asg = new AdvancedSearchGroup();
                listASG.add(asg);
                AdvancedSearchItem asi = new AdvancedSearchItem();
                asg.getListChildren().add(asi);
                asi.setItemName("DlctNgonNguView");
                asi.setRequired(true);
                asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
                asi.getListChildren().add(asgChild);
                AdvancedSearchItem asiChild = new AdvancedSearchItem();
                asgChild.getListChildren().add(asiChild);
                asiChild.setItemName("Ma");
                asiChild.setRequired(true);
                asiChild.getListValue().add(langCode);
            } catch (Exception e) {
            }
        }
        Utils.searchadvanced("DlctTruongTtView1Iterator", listASG);
    }

    private void createForm() {
        PortletRequest request =
            (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        DCIteratorBinding truongTtView1Iterator =
            Utils.getIteratorBinding("DlctTruongTtView1Iterator");
        searchPanel.getChildren().clear();
        tableDonVi.getChildren().clear();
        String chiTietUrl =
            (String)request.getPortletSession().getAttribute("chitieturl");
        String loaiDonViId =
            (String)request.getPortletSession().getAttribute("loaidonviid");
        String langCode =
            (String)request.getPortletSession().getAttribute("langcode");

        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();
        ValueExpression valueExp;
        RichColumn column = new RichColumn();
        column.setSeparateRows(true);
        column.setAlign(RichColumn.ALIGN_CENTER);
        column.setHeaderText("STT");
        //column.setRowHeader("unstyled");
        column.setSortable(false);
        column.setNoWrap(false);
        column.setWidth("25");
        RichOutputText outputText = new RichOutputText();
        valueExp =
                elFactory.createValueExpression(elContext, "#{row['STT']}", Object.class);
        outputText.setValueExpression("value", valueExp);
        column.getChildren().add(outputText);
        tableDonVi.getChildren().add(column);
        truongTtView1Iterator.setRangeSize(-1);
        Row[] rows = truongTtView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        boolean firstCol = true;
        for (int i = 0; i < rows.length; i++) {
            String ten = (String)rows[i].getAttribute("TenTruong");
            Number kieuDuLieu = (Number)rows[i].getAttribute("KieuDuLieu");
            Number viTriHienThi = (Number)rows[i].getAttribute("ViTriHienThi");
            String tablePortletColumnWidth = (String)rows[i].getAttribute("TablePortletColumnWidth");
            String tablePortletColumnAlign = (String)rows[i].getAttribute("TablePortletColumnAlign");
            Row loopRow = rows[i];
            Row rootRow = null;
            while (loopRow != null) {
                rootRow = loopRow;
                loopRow =
                        (Row)loopRow.getAttribute("DlctTruongTtTuIdDlctTruongTtView");
            }
            String rootId = ((Number)rootRow.getAttribute("Id")).toString();
            String rootRowKey = rootRow.getKey().toStringFormat(false);
            if (viTriHienThi != null && kieuDuLieu != null) {
                int viTri = viTriHienThi.intValue();
                int kieu = kieuDuLieu.intValue();
                if ((Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SEARCH.getId() &
                     viTri) ==
                    Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SEARCH.getId()) {
                    List<UIComponent> components =
                        createSearchComponent(rows[i].getKey().toStringFormat(false),
                                              rootRowKey, ten, kieu);
                    if (components != null) {
                        searchPanel.getChildren().addAll(components);
                    }
                }
                if ((Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_TABLE.getId() &
                     viTri) ==
                    Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_TABLE.getId()) {
                    if (kieu ==
                        Utils.ENUM_KIEU_DU_LIEU.IN_OUT_KIEM_TOAN_VIEN.getId() ||
                        kieu ==
                        Utils.ENUM_KIEU_DU_LIEU.KIEM_TOAN_VIEN.getId() ||
                        kieu ==
                        Utils.ENUM_KIEU_DU_LIEU.SL_KIEM_TOAN_VIEN.getId()) {
                        // khong dua ra giao dien bang
                    } else {
                        if (firstCol) {
                            column = new RichColumn();
                            column.setHeaderText(ten);
                            column.setNoWrap(false);
                            //column.setRowHeader("unstyled");
                            column.setId("colDautien");
                            //column.setStyleClass("AFStretchWidth");
                            column.setSortable(false);
                            if(tablePortletColumnAlign!=null&&tablePortletColumnAlign.isEmpty()==false){
                                column.setAlign(tablePortletColumnAlign);
                            }
                            if(tablePortletColumnWidth!=null&&tablePortletColumnWidth.isEmpty()==false){
                               column.setWidth(tablePortletColumnWidth);
                            }
                            RichGoLink goLink = new RichGoLink();
                            goLink.setTargetFrame("_parent");
                            valueExp =
                                    elFactory.createValueExpression(elContext,
                                                                    chiTietUrl +
                                                                    "?donviid=#{row['" +
                                                                    ROW_KEY +
                                                                    "']}" +
                                                                    (loaiDonViId ==
                                                                     null ?
                                                                     "" :
                                                                     "&loaidonviid=" +
                                                                     loaiDonViId) +
                                                                    (langCode ==
                                                                     null ?
                                                                     "" :
                                                                     "&langcode=" +
                                                                     langCode),
                                                                    Object.class);
                            goLink.setValueExpression("destination", valueExp);
                            valueExp =
                                    elFactory.createValueExpression(elContext,
                                                                    "#{row['" +
                                                                    rootId +
                                                                    "']}",
                                                                    Object.class);
                            goLink.setValueExpression("text", valueExp);
                            column.getChildren().add(goLink);
                            tableDonVi.getChildren().add(column);
                            tableDonVi.setColumnStretching("column:colDautien");
                            firstCol = false;
                        } else if (kieu ==
                                   Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                            column = new RichColumn();
                            column.setHeaderText(ten);
                            column.setNoWrap(false);
                            if(tablePortletColumnAlign!=null&&tablePortletColumnAlign.isEmpty()==false){
                                column.setAlign(tablePortletColumnAlign);
                            }
                            if(tablePortletColumnWidth!=null&&tablePortletColumnWidth.isEmpty()==false){
                               column.setWidth(tablePortletColumnWidth);
                            }else{
                                column.setWidth("50");
                            }
                            RichGoLink goLink = new RichGoLink();
                            goLink.setTargetFrame("_parent");
                            valueExp =
                                    elFactory.createValueExpression(elContext,
                                                                    "#{row['" +
                                                                    rootId +
                                                                    LINK_DES +
                                                                    "']}",
                                                                    Object.class);
                            goLink.setValueExpression("destination", valueExp);
                            valueExp =
                                    elFactory.createValueExpression(elContext,
                                                                    "#{row['" +
                                                                    rootId +
                                                                    "']}",
                                                                    Object.class);
                            goLink.setValueExpression("text", valueExp);
                            column.getChildren().add(goLink);
                            tableDonVi.getChildren().add(column);
                        } else if (kieu ==
                                   Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                            column = new RichColumn();
                            column.setHeaderText(ten);
                            column.setNoWrap(false);
                            if(tablePortletColumnAlign!=null&&tablePortletColumnAlign.isEmpty()==false){
                                column.setAlign(tablePortletColumnAlign);
                            }
                            if(tablePortletColumnWidth!=null&&tablePortletColumnWidth.isEmpty()==false){
                               column.setWidth(tablePortletColumnWidth);
                            }else{
                                column.setWidth("50");
                            }
                            RichGoLink goLink = new RichGoLink();
                            goLink.setTargetFrame("_parent");
                            valueExp =
                                    elFactory.createValueExpression(elContext,
                                                                    "#{row['" +
                                                                    rootId +
                                                                    LINK_DES +
                                                                    "']}",
                                                                    Object.class);
                            goLink.setValueExpression("destination", valueExp);
                            valueExp =
                                    elFactory.createValueExpression(elContext,
                                                                    "#{row['" +
                                                                    rootId +
                                                                    "']}",
                                                                    Object.class);
                            goLink.setValueExpression("text", valueExp);
                            column.getChildren().add(goLink);
                            tableDonVi.getChildren().add(column);
                        } else {
                            column = new RichColumn();
                            column.setHeaderText(ten);
                            column.setSortable(false);
                            column.setNoWrap(false);
                            if(tablePortletColumnAlign!=null&&tablePortletColumnAlign.isEmpty()==false){
                                column.setAlign(tablePortletColumnAlign);
                            }
                            if(tablePortletColumnWidth!=null&&tablePortletColumnWidth.isEmpty()==false){
                               column.setWidth(tablePortletColumnWidth);
                            }else{
                                column.setWidth("50");
                            }
                            outputText = new RichOutputText();
                            if (kieu ==Utils.ENUM_KIEU_DU_LIEU.DATE.getId()){
            DateTimeConverter converter = (DateTimeConverter)FacesContext.getCurrentInstance().getApplication()
            .createConverter("javax.faces.DateTime");
                                converter.setLocale(new Locale(langCode));
                                converter.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));
                                converter.setType("date");
                                converter.setDateStyle("short");
                            outputText.setConverter(converter);
                            }
                            valueExp =
                                    elFactory.createValueExpression(elContext,
                                                                    "#{row['" +
                                                                    rootId +
                                                                    "']}",
                                                                    Object.class);
                            outputText.setValueExpression("value", valueExp);
                            column.getChildren().add(outputText);
                            tableDonVi.getChildren().add(column);
                        }
                    }
                }
            }
        }
        if (searchPanel.getChildren().size() > 0) {
            MethodExpression methodExpression =
                elFactory.createMethodExpression(elContext, "#{dsct.timKiem}",
                                                 null,
                                                 new Class[] { ActionEvent.class });
            valueExp =
                    elFactory.createValueExpression(elContext, getResource("TIM_KIEM"),
                                                    Object.class);
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            RichCommandButton buttonSearch = new RichCommandButton();
            buttonSearch.setPartialSubmit(true);
            buttonSearch.setId("searchButton");
            buttonSearch.setValueExpression("text", valueExp);
            buttonSearch.getAttributes().put("actionListener",
                                             methodExpressionMethodBinding);
            searchPanel.getChildren().add(buttonSearch);
        }
        AdfFacesContext.getCurrentInstance().addPartialTarget(tableDonVi);
        AdfFacesContext.getCurrentInstance().addPartialTarget(searchPanel);
    }

    private void getValue(int pageNum) {
        resetPaging("DlctDonViView1Iterator", pageNum);
        DCIteratorBinding donViView1Iterator =
            Utils.getIteratorBinding("DlctDonViView1Iterator");

        List<HashMap<String, Object>> listValue = new ArrayList();
        Row[] rows = donViView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        if (rows != null) {
            String currentRowKey = "";
            if (donViView1Iterator.getCurrentRow() != null &&
                donViView1Iterator.getCurrentRowIndexInRange() >= 0 &&
                donViView1Iterator.getCurrentRowIndexInRange() <
                donViView1Iterator.getRangeSize()) {
                currentRowKey =
                        donViView1Iterator.getCurrentRow().getKey().toStringFormat(false);
            }
            RowKeySet rowKeySet = tableDonVi.getSelectedRowKeys();
            if (rowKeySet == null) {
                rowKeySet = new RowKeySetImpl();
                tableDonVi.setSelectedRowKeys(rowKeySet);
            }
            rowKeySet.removeAll();
            for (int i = 0; i < rows.length; i++) {
                donViView1Iterator.setCurrentRowIndexInRange(i);
                String rowKey =
                    donViView1Iterator.getCurrentRow().getKey().toStringFormat(false);
                if (currentRowKey == null || currentRowKey.isEmpty()) {
                    currentRowKey = rowKey;
                }
                if (currentRowKey.equals(rowKey)) {
                    rowKeySet.add(i);
                }
                HashMap<String, Object> mapValue = new HashMap();
                mapValue.put("STT",
                             donViView1Iterator.getRangeStart() + i + 1);
                mapValue.put(ROW_KEY, rowKey);
                DCIteratorBinding gtDvTtView1Iterator =
                    Utils.getIteratorBinding("DlctGtDvTtView1Iterator");
                gtDvTtView1Iterator.setRangeSize(-1);
                Row[] rowsGtTt = gtDvTtView1Iterator.getAllRowsInRange();
                if (rowsGtTt == null) {
                    rowsGtTt = new Row[] { };
                }
                for (int j = 0; j < rowsGtTt.length; j++) {
                    Row truongTtRow =
                        (Row)rowsGtTt[j].getAttribute("DlctTruongTtView");
                    if (truongTtRow != null) {
                        Number id = (Number)truongTtRow.getAttribute("Id");
                        Number kieuDuLieu =
                            (Number)truongTtRow.getAttribute("KieuDuLieu");
                        if (id != null && kieuDuLieu != null) {
                            int kieu = kieuDuLieu.intValue();
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                Number valNumber =
                                    (Number)rowsGtTt[j].getAttribute("ValNumber");
                                if (valNumber != null) {
                                    mapValue.put(id.toString(),
                                                 valNumber.toString());
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                String valVarchar =
                                    (String)rowsGtTt[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    mapValue.put(id.toString(), valVarchar);
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                String valVarchar =
                                    (String)rowsGtTt[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    String link = valVarchar.toLowerCase();
                                    if (link.startsWith("http://") == false) {
                                        link = "http://" + link;
                                    }
                                    mapValue.put(id.toString() + LINK_DES,
                                                 link);
                                    mapValue.put(id.toString(), valVarchar);
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                String valVarchar =
                                    (String)rowsGtTt[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    String link =
                                        "mailto:" + valVarchar.toLowerCase();
                                    mapValue.put(id.toString() + LINK_DES,
                                                 link);
                                    mapValue.put(id.toString(), valVarchar);
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                oracle.jbo.domain.Date valDate =
                                    (oracle.jbo.domain.Date)rowsGtTt[j].getAttribute("ValDate");
                                if (valDate != null) {
                                    java.util.Date date = valDate.dateValue();
                                    if (date != null) {
                                        mapValue.put(id.toString(), date);
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                                ClobDomain valClob =
                                    (ClobDomain)rowsGtTt[j].getAttribute("ValClob");
                                if (valClob != null) {
                                    mapValue.put(id.toString(),
                                                 valClob.toString());
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                Row fileViewRow =
                                    (Row)rowsGtTt[j].getAttribute("HtFileView");
                                if (fileViewRow != null) {
                                    String tenFile =
                                        (String)fileViewRow.getAttribute("TenFile");
                                    if (tenFile != null) {
                                        mapValue.put(id.toString(), tenFile);
                                    }
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.LOAI_CHUNG_KHOAN.getId()) {
                                Row loaiChungKhoanRow =
                                    (Row)rowsGtTt[j].getAttribute("DlctLoaiChungKhoanView");
                                if (loaiChungKhoanRow != null) {
                                    RowSet gtLckTtRowSet =
                                        (RowSet)loaiChungKhoanRow.getAttribute("DlctGtLckTtView");
                                    String ten = "";
                                    if (gtLckTtRowSet != null) {
                                        gtLckTtRowSet.setRangeSize(-1);
                                        Row[] gtLckTtRows =
                                            gtLckTtRowSet.getAllRowsInRange();
                                        if (gtLckTtRows == null) {
                                            gtLckTtRows = new Row[] { };
                                        }
                                        for (int k = 0; k < gtLckTtRows.length;
                                             k++) {
                                            Row gtLckTtTruongTtRow =
                                                (Row)gtLckTtRows[k].getAttribute("DlctTruongTtView");
                                            Number gtLckTtKieuDuLieu =
                                                (Number)gtLckTtTruongTtRow.getAttribute("KieuDuLieu");
                                            Number gtLckTtViTriHienThi =
                                                (Number)gtLckTtTruongTtRow.getAttribute("ViTriHienThi");
                                            if (gtLckTtViTriHienThi != null &&
                                                gtLckTtKieuDuLieu != null) {
                                                int gtLckviTri =
                                                    gtLckTtViTriHienThi.intValue();
                                                int gtLckKieu =
                                                    gtLckTtKieuDuLieu.intValue();
                                                if ((Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId() &
                                                     gtLckviTri) ==
                                                    Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId()) {
                                                    if (gtLckKieu ==
                                                        Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                                        Number valNumber =
                                                            (Number)gtLckTtRows[k].getAttribute("ValNumber");
                                                        if (valNumber !=
                                                            null) {
                                                            ten =
ten + valNumber.toString() + " ";
                                                        }
                                                    }
                                                    if (gtLckKieu ==
                                                        Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                                        String valVarchar =
                                                            (String)gtLckTtRows[k].getAttribute("ValVarchar");
                                                        if (valVarchar !=
                                                            null) {
                                                            ten =
ten + valVarchar + " ";
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    mapValue.put(id.toString(), ten);
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.SAN_GIAO_DICH.getId()) {
                                Row sanGiaoDichRow =
                                    (Row)rowsGtTt[j].getAttribute("DlctSanGiaoDichView");
                                if (sanGiaoDichRow != null) {
                                    RowSet gtSgdTtRowSet =
                                        (RowSet)sanGiaoDichRow.getAttribute("DlctGtSgdTtView");
                                    String ten = "";
                                    if (gtSgdTtRowSet != null) {
                                        gtSgdTtRowSet.setRangeSize(-1);
                                        Row[] gtSgdTtRows =
                                            gtSgdTtRowSet.getAllRowsInRange();
                                        if (gtSgdTtRows == null) {
                                            gtSgdTtRows = new Row[] { };
                                        }
                                        for (int k = 0; k < gtSgdTtRows.length;
                                             k++) {
                                            Row gtLckTtTruongTtRow =
                                                (Row)gtSgdTtRows[k].getAttribute("DlctTruongTtView");
                                            Number gtLckTtKieuDuLieu =
                                                (Number)gtLckTtTruongTtRow.getAttribute("KieuDuLieu");
                                            Number gtLckTtViTriHienThi =
                                                (Number)gtLckTtTruongTtRow.getAttribute("ViTriHienThi");
                                            if (gtLckTtViTriHienThi != null &&
                                                gtLckTtKieuDuLieu != null) {
                                                int gtLckviTri =
                                                    gtLckTtViTriHienThi.intValue();
                                                int gtLckKieu =
                                                    gtLckTtKieuDuLieu.intValue();
                                                if ((Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId() &
                                                     gtLckviTri) ==
                                                    Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId()) {
                                                    if (gtLckKieu ==
                                                        Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                                        Number valNumber =
                                                            (Number)gtSgdTtRows[k].getAttribute("ValNumber");
                                                        if (valNumber !=
                                                            null) {
                                                            ten =
ten + valNumber.toString() + " ";
                                                        }
                                                    }
                                                    if (gtLckKieu ==
                                                        Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                                        String valVarchar =
                                                            (String)gtSgdTtRows[k].getAttribute("ValVarchar");
                                                        if (valVarchar !=
                                                            null) {
                                                            ten =
ten + valVarchar + " ";
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    mapValue.put(id.toString(), ten);
                                }
                            }
                        }
                    }
                }
                listValue.add(mapValue);
            }
            if (currentRowKey != null && currentRowKey.isEmpty() == false) {
                donViView1Iterator.setCurrentRowWithKey(currentRowKey);
            }
        }
        tableDonVi.setValue(listValue);
        AdfFacesContext.getCurrentInstance().addPartialTarget(tableDonVi);
    }

    private void resetPaging(String iteratorName, int pageNum) {
        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();
        pagingPanel.getChildren().clear();
        DCIteratorBinding iterator = Utils.getIteratorBinding(iteratorName);
        int rowCount = (int)iterator.getEstimatedRowCount();
        int pageSize = 20; //Utils.getPageSize("HtCauHinhView1Iterator");
        int pageCount = 1;
        if (rowCount > pageSize) {
            if (rowCount % pageSize == 0) {
                pageCount = rowCount / pageSize;
            } else {
                pageCount = rowCount / pageSize + 1;
            }
        }

        if (pageNum < 1) {
            pageNum = 1;
        }
        if (pageNum > pageCount) {
            pageNum = pageCount;
        }
        int first = 1;
        if (pageNum < 3) {
            first = 1;
        } else if (pageNum + 5 > pageCount) {
            if (pageNum + 2 > pageCount) {
                if (pageCount - 4 < 1)
                    first = 1;
                else {
                    first = pageCount - 4;
                }
            } else {
                if (pageCount < 6) {
                    first = 1;
                } else {
                    first = pageNum - 2;
                }
            }
        } else {
            first = pageNum - 2;
        }

        MethodExpression methodExpression =
            elFactory.createMethodExpression(elContext, "#{dsct.changePage}",
                                             null,
                                             new Class[] { ActionEvent.class });
        MethodExpressionMethodBinding methodExpressionMethodBinding =
            new MethodExpressionMethodBinding(methodExpression);
        RichCommandLink commandLink = new RichCommandLink();
        commandLink.setPartialSubmit(true);
        commandLink.setText(getResource("PREV"));
        commandLink.getAttributes().put("actionListener",
                                        methodExpressionMethodBinding);
        commandLink.getAttributes().put("pageNum", pageNum - 1);
        commandLink.setInlineStyle("margin-right: 5px;");
        pagingPanel.getChildren().add(commandLink);
        if (pageNum == 1) {
            commandLink.setDisabled(true);
        } else {
            commandLink.setDisabled(false);
        }
        if(pageNum>3){
        methodExpression =
            elFactory.createMethodExpression(elContext, "#{dsct.changePage}",
                                             null,
                                             new Class[] { ActionEvent.class });
        methodExpressionMethodBinding =
            new MethodExpressionMethodBinding(methodExpression);
            RichCommandLink commandLinkFirst = new RichCommandLink();
            commandLinkFirst.setPartialSubmit(true);
            commandLinkFirst.setText("" +1);
            commandLinkFirst.getAttributes().put("actionListener",
                                            methodExpressionMethodBinding);
            commandLinkFirst.getAttributes().put("pageNum", 1);
            commandLinkFirst.setInlineStyle("margin:0 2px;");
            pagingPanel.getChildren().add(commandLinkFirst);
            RichOutputText outputText=new RichOutputText();
            outputText.setValue("...");
            pagingPanel.getChildren().add(outputText);
        }
        for (int i = first, j = 0; i <= pageCount && j < 5; i++, j++) {
            methodExpression =
                    elFactory.createMethodExpression(elContext, "#{dsct.changePage}",
                                                     null,
                                                     new Class[] { ActionEvent.class });
            methodExpressionMethodBinding =
                    new MethodExpressionMethodBinding(methodExpression);
            commandLink = new RichCommandLink();
            commandLink.setPartialSubmit(true);
            if (i == pageNum) {
                commandLink.setDisabled(true);
            }
            if(i==pageCount){
            commandLink.setText("" + i+"["+rowCount+"]");
            }else{
                commandLink.setText("" + i);
            }
            commandLink.setInlineStyle("margin:0 2px;");
            commandLink.getAttributes().put("actionListener",
                                            methodExpressionMethodBinding);
            commandLink.getAttributes().put("pageNum", i);
            pagingPanel.getChildren().add(commandLink);
        }
        if (pageNum+2 < pageCount) {
        methodExpression =
                elFactory.createMethodExpression(elContext, "#{dsct.changePage}",
                                                 null,
                                                 new Class[] { ActionEvent.class });
        methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            RichOutputText outputText=new RichOutputText();
            outputText.setValue("...");
        pagingPanel.getChildren().add(outputText);
            
            RichCommandLink commandLinkLast = new RichCommandLink();
            commandLinkLast.setPartialSubmit(true);
            commandLinkLast.setText("" + pageCount+"["+rowCount+"]");
            commandLinkLast.getAttributes().put("actionListener",
                                            methodExpressionMethodBinding);
            commandLinkLast.getAttributes().put("pageNum", pageCount);
            commandLinkLast.setInlineStyle("margin:0 2px;");
        pagingPanel.getChildren().add(commandLinkLast);
        }
        methodExpression =
                elFactory.createMethodExpression(elContext, "#{dsct.changePage}",
                                                 null,
                                                 new Class[] { ActionEvent.class });
        methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
        commandLink = new RichCommandLink();
        commandLink.setPartialSubmit(true);
        commandLink.setText(getResource("NEXT"));
        commandLink.getAttributes().put("actionListener",
                                        methodExpressionMethodBinding);
        commandLink.getAttributes().put("pageNum", pageNum + 1);
        commandLink.setInlineStyle("margin:0 2px;");
        if (pageNum== pageCount) {
            commandLink.setDisabled(true);
        } else {
            commandLink.setDisabled(false);
        }
        pagingPanel.getChildren().add(commandLink);

        iterator.executeQuery();
        if ((pageNum) * pageSize > rowCount) {
            iterator.setRangeSize(rowCount - (pageNum - 1) * pageSize);
        } else {
            iterator.setRangeSize(pageSize);
        }
        iterator.setRangeStart((pageNum - 1) * pageSize);

        AdfFacesContext.getCurrentInstance().addPartialTarget(pagingPanel);
    }

    private List<UIComponent> createSearchComponent(String rowKey,
                                                    String rootRowKey,
                                                    String ten, int kieu) {
        List<UIComponent> result = new ArrayList();
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.getAttributes().put("rowKey", rowKey);
            inputText.getAttributes().put("rootRowKey", rootRowKey);
            inputText.setId(SEARCH_ID_PREFIX + rowKey);
            inputText.setLabel(ten);
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.getAttributes().put("rowKey", rowKey);
            inputText.getAttributes().put("rootRowKey", rootRowKey);
            inputText.setId(SEARCH_ID_PREFIX + rowKey);
            inputText.setLabel(ten);
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.getAttributes().put("rowKey", rowKey);
            inputText.getAttributes().put("rootRowKey", rootRowKey);
            inputText.setId(SEARCH_ID_PREFIX + rowKey);
            inputText.setLabel(ten);
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.getAttributes().put("rowKey", rowKey);
            inputText.getAttributes().put("rootRowKey", rootRowKey);
            inputText.setId(SEARCH_ID_PREFIX + rowKey);
            inputText.setLabel(ten);
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
            RichInputDate inputDate = new RichInputDate();
            inputDate.getAttributes().put("rowKey", rowKey);
            inputDate.getAttributes().put("rootRowKey", rootRowKey);
            inputDate.setId(SEARCH_ID_PREFIX + rowKey);
            inputDate.setLabel(ten);
            inputDate.setAutoSubmit(true);
            if (kieu ==Utils.ENUM_KIEU_DU_LIEU.DATE.getId()){
        PortletRequest request =
            (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        String langCode =
            (String)request.getPortletSession().getAttribute("langcode");
            DateTimeConverter converter = (DateTimeConverter)FacesContext.getCurrentInstance().getApplication()
            .createConverter("javax.faces.DateTime");
                                converter.setLocale(new Locale(langCode));
                                converter.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));
                                converter.setType("date");
                                converter.setDateStyle("short");
            inputDate.setConverter(converter);
            }
            result.add(inputDate);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.getAttributes().put("rowKey", rowKey);
            inputText.getAttributes().put("rootRowKey", rootRowKey);
            inputText.setId(SEARCH_ID_PREFIX + rowKey);
            inputText.setLabel(ten);
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.getAttributes().put("rowKey", rowKey);
            inputText.getAttributes().put("rootRowKey", rootRowKey);
            inputText.setId(SEARCH_ID_PREFIX + rowKey);
            inputText.setLabel(ten);
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.LOAI_CHUNG_KHOAN.getId()) {
            UISelectItems uiSelectItems = new UISelectItems();
            uiSelectItems.setValue(listSelectItemLoaiChungKhoan());
            RichSelectOneChoice selectOneChoice = new RichSelectOneChoice();
            selectOneChoice.getAttributes().put("rowKey", rowKey);
            selectOneChoice.getAttributes().put("rootRowKey", rootRowKey);
            selectOneChoice.setId(SEARCH_ID_PREFIX + rowKey);
            selectOneChoice.setLabel(ten);
            selectOneChoice.getChildren().clear();
            selectOneChoice.getChildren().add(uiSelectItems);
            selectOneChoice.setValuePassThru(true);
            selectOneChoice.setAutoSubmit(true);
            result.add(selectOneChoice);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.SAN_GIAO_DICH.getId()) {
            UISelectItems uiSelectItems = new UISelectItems();
            uiSelectItems.setValue(listSelectItemSanGiaoDich());
            RichSelectOneChoice selectOneChoice = new RichSelectOneChoice();
            selectOneChoice.getAttributes().put("rowKey", rowKey);
            selectOneChoice.getAttributes().put("rootRowKey", rootRowKey);
            selectOneChoice.setId(SEARCH_ID_PREFIX + rowKey);
            selectOneChoice.setLabel(ten);
            selectOneChoice.getChildren().clear();
            selectOneChoice.getChildren().add(uiSelectItems);
            selectOneChoice.setValuePassThru(true);
            selectOneChoice.setAutoSubmit(true);
            result.add(selectOneChoice);
        }
        return result;
    }

    private List<SelectItem> listSelectItemLoaiChungKhoan() {
        List<SelectItem> listSelectItem = new ArrayList();
        DCIteratorBinding loaiChungKhoanView1Iterator =
            Utils.getIteratorBinding("DlctLoaiChungKhoanView1Iterator");
        loaiChungKhoanView1Iterator.setRangeSize(-1);
        Row[] rows = loaiChungKhoanView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        for (int i = 0; i < rows.length; i++) {
            String id = ((Number)rows[i].getAttribute("Id")).toString();
            String ten = "";

            RowSet gtLckTtRowSet =
                (RowSet)rows[i].getAttribute("DlctGtLckTtView");
            if (gtLckTtRowSet != null) {
                gtLckTtRowSet.setRangeSize(-1);
                Row[] gtLckTtRows = gtLckTtRowSet.getAllRowsInRange();
                if (gtLckTtRows == null) {
                    gtLckTtRows = new Row[] { };
                }
                for (int j = 0; j < gtLckTtRows.length; j++) {
                    Row truongTtRow =
                        (Row)gtLckTtRows[j].getAttribute("DlctTruongTtView");
                    Number kieuDuLieu =
                        (Number)truongTtRow.getAttribute("KieuDuLieu");
                    Number viTriHienThi =
                        (Number)truongTtRow.getAttribute("ViTriHienThi");
                    if (viTriHienThi != null && kieuDuLieu != null) {
                        int viTri = viTriHienThi.intValue();
                        int kieu = kieuDuLieu.intValue();
                        if ((Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId() &
                             viTri) ==
                            Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId()) {
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                Number valNumber =
                                    (Number)gtLckTtRows[j].getAttribute("ValNumber");
                                if (valNumber != null) {
                                    ten = ten + valNumber.toString() + " ";
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                String valVarchar =
                                    (String)gtLckTtRows[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    ten = ten + valVarchar + " ";
                                }
                            }
                        }
                    }
                }
            }

            SelectItem si = new SelectItem();
            si.setValue(id);
            si.setLabel(ten);
            listSelectItem.add(si);
        }
        return listSelectItem;
    }

    private List<SelectItem> listSelectItemSanGiaoDich() {
        List<SelectItem> listSelectItem = new ArrayList();
        DCIteratorBinding sanGiaoDichView1Iterator =
            Utils.getIteratorBinding("DlctSanGiaoDichView1Iterator");
        sanGiaoDichView1Iterator.setRangeSize(-1);
        Row[] rows = sanGiaoDichView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        for (int i = 0; i < rows.length; i++) {
            String id = ((Number)rows[i].getAttribute("Id")).toString();
            String ten = "";
            RowSet gtLckTtRowSet =
                (RowSet)rows[i].getAttribute("DlctGtSgdTtView");
            if (gtLckTtRowSet != null) {
                gtLckTtRowSet.setRangeSize(-1);
                Row[] gtLckTtRows = gtLckTtRowSet.getAllRowsInRange();
                if (gtLckTtRows == null) {
                    gtLckTtRows = new Row[] { };
                }
                for (int j = 0; j < gtLckTtRows.length; j++) {
                    Row truongTtRow =
                        (Row)gtLckTtRows[j].getAttribute("DlctTruongTtView");
                    Number kieuDuLieu =
                        (Number)truongTtRow.getAttribute("KieuDuLieu");
                    Number viTriHienThi =
                        (Number)truongTtRow.getAttribute("ViTriHienThi");
                    if (viTriHienThi != null && kieuDuLieu != null) {
                        int viTri = viTriHienThi.intValue();
                        int kieu = kieuDuLieu.intValue();
                        if ((Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId() &
                             viTri) ==
                            Utils.ENUM_VI_TRI_HIEN_THI.PORTLET_SELECT.getId()) {
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                Number valNumber =
                                    (Number)gtLckTtRows[j].getAttribute("ValNumber");
                                if (valNumber != null) {
                                    ten = ten + valNumber.toString() + " ";
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                String valVarchar =
                                    (String)gtLckTtRows[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    ten = ten + valVarchar + " ";
                                }
                            }
                        }
                    }
                }
            }
            SelectItem si = new SelectItem();
            si.setValue(id);
            si.setLabel(ten);
            listSelectItem.add(si);
        }
        return listSelectItem;
    }

    private String getResource(String resourceKey) {
        PortletRequest request =
            (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        String langCode =
            (String)request.getPortletSession().getAttribute("langcode");
        if (langCode == null) {
            langCode = DEFAULT_LANGCODE;
        }
        Locale locale = new Locale(langCode);
        ResourceBundle bundle =
            ResourceBundle.getBundle("portlet.dsct.resource.DsctBundle",
                                     locale);
        return bundle.getString(resourceKey);
    }

    public String getTieuDe() {
        PortletRequest request =
            (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        return request.getParameter("tieude");
    }

    public String getTimKiemLabel() {
        return getResource("timkiemdulieucongty");
    }

    public String getDanhSachLabel() {
        return getResource("danhsachcongty");
    }

    public void setSearchPanel(RichPanelFormLayout searchPanel) {
        this.searchPanel = searchPanel;
    }

    public RichPanelFormLayout getSearchPanel() {
        return searchPanel;
    }

    public void setTableDonVi(RichTable tableDonVi) {
        this.tableDonVi = tableDonVi;
    }

    public RichTable getTableDonVi() {
        return tableDonVi;
    }

    public void setPagingPanel(RichPanelGroupLayout pagingPanel) {
        this.pagingPanel = pagingPanel;
    }

    public RichPanelGroupLayout getPagingPanel() {
        return pagingPanel;
    }
}
